package com.otojob.controller;


import com.otojob.dto.PageDto;
import com.otojob.entity.vo.CompanyCertification;
import com.otojob.mapper.UserJobMapper;
import com.otojob.service.*;
import com.otojob.utils.JwtUtils;
import com.otojob.utils.Results;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author TingFeng
 * @since 2022-03-18
 */

@Api(value = "MineController", tags = "我的页")
@CrossOrigin
@RestController
@RequestMapping("/mine")
public class MineController {


    @Autowired
    private UserJobService userJobService;
    @Autowired
    private UserService userService;
    @Autowired
    private OssService ossService;
    @Autowired
    private CompanyService companyService;
    @Resource
    private HttpServletRequest request;
    @Autowired
    private JobService jobService;


    @ApiOperation("查找用户")
    @GetMapping("/findUserById")
    public  Results findUserById(){
        Integer id = JwtUtils.getMemberIdByJwtToken(request);
        return userService.findUserById(id);
    }

    @ApiOperation("查找简历是否存在")
    @GetMapping("/findMyResumeTF")
    public  Results findMyResumeTF(){
        return userService.findMyResumeTF();
    }

    @ApiOperation("上传简历")
    @PostMapping("/upLoadResume")
    public String upLoadResume(MultipartFile file){
        return ossService.upLoadResume(file);
    }

    @ApiOperation("添加简历")
    @PostMapping("/addResume")
    public Results addResume(String url){
        return userService.addResume(url);
    }

    @ApiOperation("删除简历")
    @DeleteMapping("/deleteResume")
    public Results deleteResume(){
        return userService.deleteResume();
    }

    @ApiOperation("获取简历")
    @GetMapping("/getResume")
    public Results getResume(){
        return userService.getResume();
    }

    @ApiOperation("上传头像获取url")
    @GetMapping("/upLoadPhoto")
    public Results upLoadPhoto(MultipartFile file){
        String url = ossService.upLoadUserPhoto(file);
        return Results.ok().data("url",url);
    }

    @ApiOperation("修改电话")
    @GetMapping("/updateUserTelephone")
    public Results updateUserTelephone(String telephone){
        Integer id = JwtUtils.getMemberIdByJwtToken(request);
        return userService.updateUserTelephone(telephone,id); }

    @ApiOperation("修改昵称")
    @GetMapping("/updateNikeName")
    public Results updateNikeName(String nikename){
        Integer id = JwtUtils.getMemberIdByJwtToken(request);
        return userService.updateNikeName(nikename,id);
    }

    @ApiOperation("修改头像")
    @GetMapping("/updatePhoto")
    public Results updatePhoto(String url){

        Integer id = JwtUtils.getMemberIdByJwtToken(request);
        return userService.updatePhoto(url,id);
    }

    @ApiOperation("修改求职宣言")
    @GetMapping("/updateDeclaration")
    public Results updateDeclaration(String declaration){
        Integer id = JwtUtils.getMemberIdByJwtToken(request);
        return userService.updateDeclaration(declaration,id); }

    @ApiOperation("修改性别/0男1nv")
    @GetMapping("/updateUserSex")
    public Results updateUserSex(Integer sex){
        Integer id = JwtUtils.getMemberIdByJwtToken(request);
        return userService.updateUserSex(sex,id);
    }


    @ApiOperation("查询已投递工作")
    @GetMapping("/findJobHistoryByUserId")
    public Results findJobHistoryByUserId(@Valid PageDto pageDto){
        return userJobService.findJobHistoryByUserId(pageDto);
    }
    @ApiOperation("查询收到简历列表前")
    @GetMapping("/findReceivedResumeListFront")
    public Results findReceivedResumeListFront(){
        return userJobService.findReceivedResumeListFront();
    }
    @ApiOperation("查询收到简历列表")
    @GetMapping("/findReceivedResumeList")
    public Results findReceivedResumeList(@Valid PageDto pageDto, Integer jobId){
        return userJobService.findReceivedResumeList(pageDto,jobId);
    }
    @ApiOperation("添加企业认证")
    @PostMapping("/companyCertification")
    public  Results companyCertification( @Valid @RequestBody CompanyCertification companyCertification){
        System.out.println(companyCertification.getPhoto());
        System.out.println(companyCertification.getTelephone());
        return companyService.companyCertification(companyCertification);
    }
    @ApiOperation("下线删除职位")
    @PutMapping("/deleteJobById")
    public  Results deleteJobById(@NotNull
                                  @Min(0)
                                  @RequestParam("id")Integer id){
        int userId = JwtUtils.getMemberIdByJwtToken(request);
        return  jobService.deleteJobById(id,userId);
    }


}

